<template>
  <div class="navBox">
    <div class="navClose" v-if="!open">
      <div class="navList">
        <div :class="['navItem',index == 0? 'choosed':'']" v-for="(item,index) in catList" :key="index">
          <div class="navPic">
            <img src="@/assets/images/diy/default_img.png" alt="" v-if="item.pic_url == ''"/>
            <img :src="item.pic_url" alt="" v-else/>
          </div>
          <span>{{item.name}}</span>
        </div>
      </div>
      <div class="open" @click.stop="open = !open">
        <span>展</span>
        <span>开</span>
        <span class="iconfont icon-weibiaoti-17"></span>
      </div>
    </div>
    <div class="navOpenBox" v-else>
      <div class="navOpen">
        <div class="navList">
          <div class="itemBox" v-for="(item,index) in catList" :key="index">
            <div :class="['navItem',index == 0?'choosed':'']">
              <div class="navPic">
                <img src="@/assets/images/diy/default_img.png" alt="" v-if="item.pic_url == ''"/>
                <img :src="item.pic_url" alt="" v-else/>
              </div>
              <span>{{item.name}}</span>
            </div>
          </div>
        </div>
        <div class="close" @click.stop="open = !open">
          <span>点击收起</span>
          <span class="iconfont icon-weibiaoti-16"></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    catList:{
      type:Array,
      default:() => {
        return []
      }
    }
  },
  data() {
    return {
      open: false,
    };
  },
};
</script>

<style lang="scss" scoped>
.navBox {
  width: 100%;
}
.navOpenBox {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
}
.navClose {
  width: 100%;
  height: 84px;
  background-color: #fff;
  display: flex;
  .navList {
    flex: auto;
    height: 100%;
    padding-left: 16px;
    display: flex;
    overflow-x: auto;
    flex-wrap: nowrap;
    .navItem {
      margin-right: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      .navPic {
        width: 46px;
        height: 46px;
        border-radius: 50%;
        margin-bottom: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        img {
          width: 40px;
          height: 40px;
          border-radius: 50%;
        }
      }
      span {
        font-size: 11px;
        color: #262626;
        white-space: nowrap;
      }
    }
    .choosed {
      .navPic {
        border: 1px solid #f0250e;
      }
      span {
        padding: 2px 8px;
        background-color: #f0250e;
        border-radius: 99px;
        color: #fff;
        font-weight: 600;
      }
    }
  }
  .navList::-webkit-scrollbar {
    display: none;
  }
  .open {
    width: 36px;
    min-width: 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #262626;
    font-weight: 600;
    font-family: PingFang SC;
    box-shadow:-10px 0px 6px -6px rgba(0, 0, 0, 0.16);
    cursor: pointer;
    .iconfont {
      font-size: 12px;
    }
  }
}
.navOpen {
  width: 100%;
  background-color: #fff;
  border-radius: 0 0 12px 12px;
  .navList {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    .itemBox {
      width: 20%;
      display: flex;
      justify-content: center;
      .navItem {
        display: flex;
        flex-direction: column;
        align-items: center;
        margin: 5px;
        box-sizing: border-box;
        .navPic {
          width: 56px;
          height: 56px;
          border-radius: 50%;
          margin-bottom: 6px;
          display: flex;
          align-items: center;
          justify-content: center;
          box-sizing: border-box;
          img {
            width: 46px;
            height: 46px;
            border-radius: 50%;
          }
        }
        span {
          font-size: 11px;
          color: #262626;
          white-space: nowrap;
        }
      }
      .choosed {
        .navPic {
          border: 1px solid #f0250e;
        }
        span {
          padding: 2px 6px;
          background-color: #f0250e;
          border-radius: 99px;
          color: #fff;
          font-weight: 600;
        }
      }
    }
  }
  .close {
    cursor: pointer;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    border-top: 1px solid #f6f6f6;
    font-size: 12px;
    color: #8c8c8c;
    .iconfont {
      font-size: 12px;
      color: #262626;
      margin-left: 6px;
    }
  }
}
</style>